import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.joda.time.DateTime;

import java.io.FileOutputStream;
import java.io.IOException;

public class ExcelWriteTest {
	public String PATH ="D:\\java_learning\\8.小工具\\shimmer-POI\\src\\main\\resources\\";

	public void testWrite03() throws IOException {
		//	1.创建工作簿 03
		Workbook workbook = new HSSFWorkbook();
		//  2.创建工作表
		Sheet sheet = workbook.createSheet("打卡表03");
		//	3.创建单元行
		Row row1 = sheet.createRow(0);
		//  4.创建单元格
		Cell cell11 = row1.createCell(0);
		cell11.setCellValue("日期");
		Cell cell12 = row1.createCell(1);
		cell12.setCellValue("完成情况");

		Row row2 = sheet.createRow(1);
		Cell cell21 = row2.createCell(0);
		String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
		cell21.setCellValue(time);
		Cell cell22 = row2.createCell(1);
		cell22.setCellValue("圆满完成");

		//  5.生成一个IO流，03版以xls结尾
		FileOutputStream os = new FileOutputStream(PATH + "打卡表03.xls");
		workbook.write(os);

		//	6.关闭流
		workbook.close();
		System.out.println("打卡表03.xls输出完毕！");
	}

	public void testWrite07() throws IOException {
		//	1.创建工作簿 07
		Workbook workbook = new XSSFWorkbook();
		//  2.创建工作表
		Sheet sheet = workbook.createSheet("打卡表07");
		//	3.创建单元行
		Row row1 = sheet.createRow(0);
		//  4.创建单元格
		Cell cell11 = row1.createCell(0);
		cell11.setCellValue("日期");
		Cell cell12 = row1.createCell(1);
		cell12.setCellValue("完成情况");

		Row row2 = sheet.createRow(1);
		Cell cell21 = row2.createCell(0);
		String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
		cell21.setCellValue(time);
		Cell cell22 = row2.createCell(1);
		cell22.setCellValue("圆满完成");

		//  5.生成一个IO流，03版以xls结尾
		FileOutputStream os = new FileOutputStream(PATH + "打卡表07.xlsx");
		workbook.write(os);

		//	6.关闭流
		workbook.close();
		System.out.println("打卡表07.xls输出完毕！");
	}
}
